# -*- coding: cp936 -*-
import sys, pygame
import random
from pygame.locals import *

pygame.init()

#砖块, 块 = 24, 20
tiles, block = 24, 20
#尺寸 = 宽度, 高度 = (砖块 * 块), (砖块 * 块 + 10)
size = width, height = (tiles * block), (tiles * block + 10)
#大厅, 墙, 边界, 多余的 = 0, 1, 2, 3
hall, wall, boundary, extra = 0, 1, 2, 3
#白色, 灰色, 黑色 = (255, 255, 255), (100, 100, 100), (0, 0, 0)
white, grey, black = (255, 255, 255), (100, 100, 100), (0, 0, 0)
screen = pygame.display.set_mode(size)

def make_maze():
    #global 迷宫, 玩家, 结束, 移动
    global maze, player, end, moves
    maze = [boundary] * tiles
    maze += ([boundary] + [hall] * (tiles - 2) + [boundary]) * (tiles - 2)
    maze += [boundary] * tiles
    
def draw_tile(func, color, pos):
    #求出小矩形的左上角的坐标
    left = (pos % tiles) * block
    top = (pos / tiles) * block
    
    #绘制一个矩形
    #screen 表示区域
    #color 颜色
    #（left，top） 小矩形左上角的左边
    #（block，block）小矩形的宽高
    func(screen, color, (left, top, block, block))

def draw_maze():
    #pos 表示maze列表中 val 所对应的下标
    for pos, val in enumerate(maze):
        color = white if val == hall else black
        draw_tile(pygame.draw.rect, color, pos)

make_maze()
draw_maze()

while True:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit()
   

    

    pygame.display.flip()
